<?php
/** @noinspection PhpUnused */

namespace app\shop\model\user;

use app\shop\model\BaseModel;

class UserModel extends BaseModel
{
    protected $name = 'shop_user';

    public function searchPhoneAttr($query, $value): void
    {
        $query->where('phone', $value);
    }

    public function getMoneyAttr($value): string
    {
        return bcdiv($value, 100, 2);
    }

    public function setMoneyAttr($value): string
    {
        return bcmul($value, 100, 2);
    }

    public function getScoreAttr($value): string
    {
        return bcdiv($value, 100, 2);
    }

    public function setSoneyAttr($value): string
    {
        return bcmul($value, 100, 2);
    }

    /**
     * 获取用户信息【过滤敏感字段】
     * @return UserModel
     */
    public function getUserInfo(): UserModel
    {
        return $this->hidden([
            'group_id', 'login_failure', 'join_ip', 'join_time', 'motto', 'password',
            'salt', 'status', 'create_time', 'update_time'
        ]);
    }
}
